/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package view.contact;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.*;
import model.Contact;

/**
 * Small panel that can be included in MainWindow
 * @author Gautier
 */
public class SmallDisplay extends JPanel implements ActionListener{

    private JLabel name;
    private JButton button;

    /**
     * Contact's object
     */
    protected Contact co;
    private ArrayList al;
    
    /**
     * Constructor
     * @param c Contact object
     * @param a Arraylist of contacts
     */
    public SmallDisplay(Contact c, ArrayList a) {
        super();
        c.setSd(this);
        co=c;
        al=a;
        this.setSize(250,40);
        this.setPreferredSize(new Dimension(250,40));
        this.setBorder(BorderFactory.createLineBorder(Color.BLACK));
        
        name = new JLabel(c.getName()+" "+ c.getFirstName());
        this.add(name);
        
        button = new JButton("View");
        button.addActionListener(this);
        this.add(button);
    }
    
    /**
     * Function to refresh a SmallDisplay in case of edition of a Contact
     */
    public void refreshDisplay() {
        this.name.setText( co.getName()+" "+ co.getFirstName());
    }

    public void actionPerformed(ActionEvent e) {
        new LargeDisplay(co, al);
    }
    
}
